package exam.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	/**
	 * YYYYMMDD_HHMMSS
	 */
	public static final String YYYYMMDD_HHMMSS = "yyyyMMddHHmmss";
	/**
	 * YYYYMMDD
	 */
	public static final String YYYYMMDD = "yyyyMMdd";
	/**
	 * DDMMYYYY
	 */
	public static final String DDMMYYYY_HHMMSS = "dd/MM/yyyy HH:mm:ss";
	
	/**
	 * dateFormat
	 */
	private static SimpleDateFormat dateFormat;
	
	/**
	 * convertDateToString
	 * @param date
	 * @param formatString
	 * @return String
	 */
	public static String convertDateToString(Date date, String formatString) {
		dateFormat = new SimpleDateFormat(formatString);
		return dateFormat.format(date);
	}
	
	/**
	 * convertStringToDate
	 * @param strDate
	 * @param formatString
	 * @return Date
	 */
	public static Date convertStringToDate(String strDate, String formatString) {
		dateFormat = new SimpleDateFormat(formatString);
		Date date = null;
		try {
			date = dateFormat.parse(strDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
}
